package com.cq.xjms.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/***
 * @author caiqiang
 * @version 1
 */
@Entity
@Table(name = "Student")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@NamedQueries( {
	@NamedQuery(name = "Student.queryByClazzId", query ="select s from Student s where s.clazz.id=:clazz_id"),
	@NamedQuery(name = "Student.query", query ="select s from Student s where s.stuNo=:stuNo"),
	@NamedQuery(name = "Student.queryByName", query ="select s from Student s where s.name =:studentName"),
	@NamedQuery(name = "Student.queryByPassword", query ="select s from Student s where s.password =:password"),
	@NamedQuery(name = "Student.queryById", query ="select s from Student s left join fetch s.clazz left join fetch s.clazz.department left join fetch" +
				" s.clazz.department.institute where s.id=:id "),
				@NamedQuery(name = "Student.login", query ="select u from Student u where  u.stuNo=:userNo and u.password=:password ")		
})	
public class Student extends BaseEntity{
	
	private static final long serialVersionUID = 8825616410502042893L;
	public static final String STUDENT_QUERY = "Student.query";
	public static final String STUDENT_QUERYBYID = "Student.queryById";
	public static final String STUDENT_QUERYBYCLAZZID = "Student.queryByClazzId";
	public static final String STUDENT_QUERYBYNAME = "Student.queryByName";
	public static final String STUDENT_QUERYBYPASSWORD = "Student.queryByPassword";
	public static final String STUDENT_LOGIN = "Student.login";
	
	@Column(name = "NAME", length = 50, nullable = false)
	private String name; 
	
	@Column(name = "PASSWORD", length = 50, nullable = false)
	private String password;
	
	@Column(name = "SEX", length = 50)
	private String sex;
	
	@Column(name = "EMAIL", length = 50)
	private String email;
	
	@Column(name = "TEL", length = 15)
	private String tel;
	
	@Column(name = "PHONE", length = 11)
	private String phone;
	
	@Column(name = "STUNO", length = 20, nullable = false,unique = true)
	private String stuNo;
	
	@Column(name = "BIRTHDATE")
	@Temporal(TemporalType.TIMESTAMP)
	private Date birthdate;
	
	@Column(name = "CREATEDATE", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createDate = new Date();
	
	
	@Column(name="ADDRESS",length=100)
	private String address;	
	
	@ManyToOne(fetch = FetchType.LAZY)
	private Clazz clazz;
	
//	@ManyToMany(fetch = FetchType.LAZY)
//	@JoinTable(
//	        name="Score",
//	        joinColumns=@JoinColumn(name="student_id"),
//	        inverseJoinColumns=@JoinColumn(name="course_id")
//	    )
//	private List<Course> courses;
	
	@Column(name="STATUS")
	private int status;
	
	@Column(name = "IDCARD")
	private String idcard;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	
	public String getStuNo() {
		return stuNo;
	}
	public void setStuNo(String stuNo) {
		this.stuNo = stuNo;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public Clazz getClazz() {
		return clazz;
	}
	public void setClazz(Clazz clazz) {
		this.clazz = clazz;
	}
//	public List<Course> getCourses() {
//		return courses;
//	}
//	public void setCourses(List<Course> courses) {
//		this.courses = courses;
//	}
	public Date getBirthdate() {
		return birthdate;
	}
	public void setBirthdate(Date birthdate) {
		this.birthdate = birthdate;
	}
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	
}
